package com.qf.day11;

import javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec;
import java.util.Stack;

public class StackDemo02 {
    public static void main(String[] args) {
        String s = "1+((a+b)/c)+5/(2+a)";
        System.out.println(isBracketsMatched(s));
    }



    private static boolean isBracketsMatched(String s) {
        Stack<Character> stack = new Stack<>();

        for (char c : s.toCharArray()) {
            if (c == '(') {
                stack.push(c);
            } else if (c == ')') {
                if (stack.isEmpty()) {
                    return false; // 如果栈为空，但遇到了右括号，说明括号不匹配
                }
                stack.pop(); // 弹出栈顶的左括号
            }
        }

        return stack.isEmpty();
    }

}
